package com.lancoo.dictionary.data.adapter;

import java.util.List;

import com.lancoo.dictionary.R;
import com.lancoo.dictionary.data.model.SearchHistory;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class SearchHistoryAdapter extends BaseAdapter {

	private List<SearchHistory> searchHistorys;
	
	public SearchHistoryAdapter(List<SearchHistory> searchHistorys) {
		this.searchHistorys = searchHistorys;
	}

	private static class ViewHolder {
		TextView shKnowledge;
		
		public ViewHolder(View itemView) {
			shKnowledge = (TextView) itemView.findViewById(R.id.item_sh_knowledge);
			
		}
	}

	@Override
	public int getCount() {
		return searchHistorys==null?0:searchHistorys.size();
	}



	@Override
	public Object getItem(int position) {
		return searchHistorys.get(position);
	}



	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (null == convertView) {
			convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.lcdic_dic_item_search_history, null);
			holder = new ViewHolder(convertView);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.shKnowledge.setText(searchHistorys.get(position).getSearchContent());
		return convertView;
	}
	
	public void updateDataSet(List<SearchHistory> searchHistorys){
		this.searchHistorys = searchHistorys;
		notifyDataSetChanged();
	}

}
